﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using DRHotel_v1.Classes;
using DRHotel_v1.Classes.DBManagers;
using DRHotel_v1.RoomAvaAndBooking;
using DRHotel_v1.HousekeepingAndStaffMngmt;
using DRHotel_v1.UserAccountAndMultiCreation;


namespace DRHotel_v1
{
    public partial class MainForm : Form
    {
        public string name = string.Empty;
        public string pwd = string.Empty;
        public string type = string.Empty;
        public string time = DateTime.Now.ToString();
        public string staffID;
        
        //---private method for splash screen and loding---
        private SplashScreen splashScreen;
        private bool done = false;
        //---private method for splash screen and loding---

        public Form RefToLogIn { get; set; }

        public MainForm()
        {
            InitializeComponent();
            staffManagementToolStripMenuItem.MouseHover += (s, e) => staffManagementToolStripMenuItem.ShowDropDown();
            this.Load += new EventHandler(HandleFormLoad);//Load Splash Screen
            this.splashScreen = new SplashScreen();//Load Splash Screen
        }

        #region Splash Screen and Loading
        private void HandleFormLoad(object sender, EventArgs e)
        {
            this.Hide();

            Thread thread = new Thread(new ThreadStart(this.ShowSplashScreen));
            thread.Start();

            Hardworker worker = new Hardworker();
            worker.ProgressChanged += (o, ex) =>
            {
                this.splashScreen.UpdateProgress(ex.Progress);
            };

            worker.HardWorkDone += (o, ex) =>
            {
                done = true;
                this.Show();
            };

            worker.DoHardWork();
        }

        private void ShowSplashScreen()
        {
            splashScreen.Show();
            while (!done)
            {
                Application.DoEvents();
            }
            splashScreen.Close();
            this.splashScreen.Dispose();
        }
        #endregion

        #region Load Form Info
        private void MainForm_Load(object sender, EventArgs e)
        {
            tsslUsername.Text = name;
            tsslTime.Text = time;
            tsslUserType.Text = type;
            tsslStaffID.Text = staffID;
            
            if (type.Equals("Manager"))
            {
                accountManagementToolStripMenuItem1.Visible = false;
            }
            if (type.Equals("Staff"))
            {
                //roomManagementToolStripMenuItem.Enabled = false;
                roomManagementToolStripMenuItem.Visible = false;
                //itemManagementToolStripMenuItem.Visible = false;
                //accountManagementToolStripMenuItem.Visible = false;
                staffManagementToolStripMenuItem.Visible = false;
                tsbtnHousekeeping.Visible = false;
                tsbtnReport.Visible = false;
            }
        }
        #endregion

        #region Menu buttons
        private void tsbtnCheckIn_Click(object sender, EventArgs e)
        {
            CheckInFrm ckifm = new CheckInFrm();
            ckifm.ShowDialog();
        }

        private void tsbtnLogOut_Click(object sender, EventArgs e)
        {
            
            DialogResult result = MessageBox.Show("Confirm Log Out?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (result == DialogResult.Yes)
            {
                this.Close();
                this.RefToLogIn.Show();
            }
        }


        private void tsbtnRes_Click(object sender, EventArgs e)
        {
            RoomAvaSearchFrm frm = new RoomAvaSearchFrm();
            frm.MdiParent = this;
            frm.Show();
        }

        private void tsbtnCheckOut_Click(object sender, EventArgs e)
        {
            ResRecordFrm frm = new ResRecordFrm();
            frm.resList = RoomAvaAndBookingDBManager.GetReservationByStatus("Staying");
            frm.MdiParent = this;
            frm.Show();
        }

        private void reservationManagementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ResRecordFrm frm = new ResRecordFrm();
            frm.resList = RoomAvaAndBookingDBManager.GetAllReservations();
            frm.MdiParent = this;
            frm.Show();
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            CustomerRecordFrm frm = new CustomerRecordFrm();
            frm.staffID = tsslStaffID.Text;
            frm.MdiParent = this;
            frm.Show();
        }

        private void createCustomerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CustomerCreateFrm frm = new CustomerCreateFrm();
            frm.Show();
        }

        private void tsbtnHousekeeping_Click(object sender, EventArgs e)
        {
            Housekeeping frm = new Housekeeping();
            frm.MdiParent = this;
            frm.Show();
        }

        private void customersInformationChangelogToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CustomerModificationLog frm = new CustomerModificationLog();
            frm.MdiParent = this;
            frm.Show();
        }

        private void tsbtnReport_Click(object sender, EventArgs e)
        {
            
        }

        private void browseCustomerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CustomerRecordFrm frm = new CustomerRecordFrm();
            frm.MdiParent = this;
            frm.Show();
        }

        private void openStaffManagementToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StaffManagement frm = new StaffManagement();
            frm.ShowDialog();
        }

        private void accountManagementToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            UserAccountAndMultiCreationForm frm = new UserAccountAndMultiCreationForm();
            frm.ShowDialog();
        }

        private void itemManagementToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ItemManagement frm = new ItemManagement();
            frm.ShowDialog();
        }

        private void roomManagementToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            RoomManagement frm = new RoomManagement();
            frm.ShowDialog();
        }

        #endregion

    }
}
